Dart BigInt operator ~
Syntax & Examples
BigInt.operator ~ operator
The `~` operator performs bitwise negation on this BigInt.
Syntax of BigInt.operator ~
The syntax of BigInt.operator ~ operator is:
operator ~() → BigIntThis operator ~ operator of BigInt the bit-wise negate operator.
✐ Examples
1 Perform bitwise negation on positive BigInt
In this example,
- We define a positive BigInt
numwith a value of5. - We use the `~` operator to perform bitwise negation on
num. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(5);
BigInt result = ~num;
print('Bitwise negation of 5: $result');
}Output
Bitwise negation of 5: -6
2 Perform bitwise negation on negative BigInt
In this example,
- We define a negative BigInt
numwith a value of-5. - We use the `~` operator to perform bitwise negation on
num. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(-5);
BigInt result = ~num;
print('Bitwise negation of -5: $result');
}Output
Bitwise negation of -5: 4
Summary
In this Dart tutorial, we learned about operator ~ operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.